<template>
  <div>
    <div class="filter-container">
      <el-date-picker class="filter-item"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      v-model="time"
                      type="daterange"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
      </el-date-picker>
      <el-select v-model="requestParam.companyId" placeholder="请输入服务公司名称" class="filter-item"
                 clearable>
        <el-option v-for="item in shopAllList" :key="item.id"
                   :label="item.companyName" :value="item.id">
        </el-option>
      </el-select>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> 搜索</el-button>
    </div>
    <el-row :gutter="10" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <icon icon="todayOrderCount"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              订单数量
            </div>
            <count-to :start-val="0" :end-val="data.todayOrderCount" :duration="3200" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <icon icon="todayOrderCancel"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              取消数量
            </div>
            <count-to :start-val="0" :end-val="data.todayOrderCancel" :duration="3600" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <icon icon="totalOrderStore"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              存放数量
            </div>
            <count-to :start-val="0" :end-val="data.totalOrderStore" :duration="3600" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <icon icon="totalOrderFinish"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              完成数量
            </div>
            <count-to :start-val="0" :end-val="data.totalOrderFinish" :duration="3600" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="10" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <icon icon="totalAmount"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              营业金额
            </div>
            <count-to :start-val="0" :end-val="data.totalAmount" :duration="3200" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <icon icon="todayAmountRefund"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              退款金额
            </div>
            <count-to :start-val="0" :end-val="data.todayAmountRefund" :duration="3600" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <icon icon="todayAmountReceive"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              实收金额
            </div>
            <count-to :start-val="0" :end-val="data.todayAmountReceive" :duration="3600" class="card-panel-num"/>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import {proxyStatisticExpress, proxyStatisticStore} from "@/api/modules/serviceApi";

export default {
  components: {
    CountTo
  },
  data() {
    return {
      shopAllList: [],
      time: '',
      data: {
        todayOrderCount: 0,
        todayOrderCancel: 0,
        totalOrderStore: 0,
        totalOrderFinish: 0,
        totalAmount: 0,
        todayAmountRefund: 0,
        todayAmountReceive: 0,
      },
      requestParam: {
        province: '',
        city: '',
        companyId: '',
        startTime: '',
        endTime: ''
      },
      userInfo: {}
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    handleFilter() {
        this.pageRequest = {
            pageNum: 1,
            pageSize: 10,
        }
      if (this.time) {
        let timeArr = this.time;
        if (timeArr[0]) {
          this.requestParam.startTime = timeArr[0]
        }
        if (timeArr[1]) {
          this.requestParam.endTime = timeArr[1]
        }
      }
      this.getDataStore()
    },
    getDataStore() {
      this.listLoading = true
      //【API请求】----数据统计
      this.$api.proxyStatisticStore(this.requestParam).then(response => {
        this.data = response.data
        this.listLoading = false;
      }).catch((res) => {
        this.$message({message: '加载失败', type: 'error'})
      })
    },
    getUserInfo() {
      let userId = this.$store.getters.userInfo.userId;
      let userType = this.$store.getters.userInfo.userType;
      this.listLoading = true
      if ("systemUser" === userType) {
        //   总后台
        this.getDataStore();
        this.getShopAllList();
      } else {
        this.$api.getProxyInfo({
          userId: userId
        }).then(response => {
          this.userInfo = response.data
          this.listLoading = false;
          if (this.userInfo.level === 1) {
            this.requestParam.province = this.userInfo.province
          }
          if (this.userInfo.level === 2) {
            this.requestParam.city = this.userInfo.city
          }
          this.getDataStore();
          this.getShopAllList();
        }).catch((res) => {
          this.$message({message: '加载失败', type: 'error'})
        })
      }
    },
    getShopAllList() {
      this.listLoading = true
      //【API请求】----获取表格列表数据
      this.$api.getAllServiceCompanys({
        province: this.requestParam.province, city: this.requestParam.city
      }).then(response => {
        this.shopAllList = response.data
        this.listLoading = false;
      }).catch((res) => {
        this.$message({message: '列表获取失败', type: 'error'})
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 0px;

  .card-panel-col {
    margin-bottom: 20px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;

      i {
        font-size: 40px;
      }
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
